package demo6;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;

/**
 * 暴力反射可以破坏单例模式 继续new对象
 */
public class Demo3 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        Class cls = Class.forName("demo6.Student");
        //只要语法没有错误 编译器是不会报错的， 反射是运行时候才会报异常的。
     //   Object o1 = cls.newInstance();
      //  System.out.println(o1);

        Constructor c = cls.getDeclaredConstructor();
        c.setAccessible(true);
        Object o1 = c.newInstance();
        Object o2 = c.newInstance();
        System.out.println(o1);
        System.out.println(o2);
    }
}
